<?php

namespace Admin\Controller;
use Think\Controller;

class OrderController extends Controller
{

	public $orderId,$userId,$administratorId,$totalMoney,$buyDate,$importAddress,$ordercol,$exportAddress,$orderStatus,$sendName,$pickName,$sendPhone,$pickPhone,$remark;



	public function index(){
		$where['OrderStatus']=I('get.OrderStatus','1');
		$data = M('order')->field('OrderId,UserId,OrderStatus,TotalMoney,BuyDate')->where($where)->select();
		if(IS_POST){
			$OrderId=I('post.search',0,'int');
			if($OrderId!=0){
				$whereOrderId = "OrderId=$OrderId";
						$data = M('order')->field('OrderId,UserId,OrderStatus,TotalMoney,BuyDate')->where($whereOrderId)->select();
			}
		}
		//获得数据
		//视图
		$this->assign("data",$data);
		$this->assign("status",$where['OrderStatus']);
		$this->display();
	}
	/**
	 * @return   void
	 */
	public function addOrder()
	{
		// TODO: implement
	}

	/**
	 * @return   array
	 */
	public function checkOrder()
	{
		// TODO: implement
	}

	/**
	 * @return   void
	 */
	public function pay()
	{
		// TODO: implement
	}


	/**
	 * @return   void
	 */
	public function deleteOrder()
	{
		// TODO: implement
	}


	public function show(){
		$where['OrderId']=I('get.OrderId');
		$orderdata=M('order')->where($where)->find();
		$userwhere['UserId']=$orderdata['UserId'];
		$userdata=M('user')->where($userwhere)->find();
		$orderdetailwhere['order_OrderId']=$where['OrderId'];
		$orderdetaildata=M('orderdetail')->join('join goods ON orderdetail.goods_GoodId=goods.GoodId AND orderdetail.goods_Color=goods.Color AND orderdetail.goods_Version=goods.Version')->where($orderdetailwhere)->select();
		$this->assign("userdata",$userdata);
		$this->assign("orderdetaildata",$orderdetaildata);
		$this->assign("orderdata",$orderdata);
		$this->display();
	}


	/**
	 * @return   void
	 */
	public function sendGoods()
	{
		// TODO: implement
		$where['OrderId']=I('get.OrderId');
		$adminwhere['AdministratorId']=session('admin_id');
		$admindata=M('administrator')->where($adminwhere)->find();
		if(IS_POST){
			$data['ExportAddress']=I('post.ExportAddress',$admindata['Address']);
			$data['SendName']=I('post.SendName',$admindata['AdministratorName']);
			$data['SendPhone']=I('post.SendPhone',$admindata['Phone']);
			$data['OrderStatus']=2;
			$rst = M("order")->where($where)->save($data);
			if($rst===false){
				$this->error('发货失败');
			}
			//	--------------------------------------------------
			echo "<script language='javascript' type='text/javascript'>alert('发货成功')</script>";
			$url = __CONTROLLER__."/index";
			echo "<script language='javascript' type='text/javascript'>window.location.href='$url'</script>";
			return;
		}
		$where['OrderId']=I('get.OrderId');
		$orderdata=M('order')->where($where)->find();
		$userwhere['UserId']=$orderdata['UserId'];
		$userdata=M('user')->where($userwhere)->find();
		$orderdetailwhere['order_OrderId']=$where['OrderId'];
		$orderdetaildata=M('orderdetail')->join('join goods ON orderdetail.goods_GoodId=goods.GoodId AND orderdetail.goods_Color=goods.Color AND orderdetail.goods_Version=goods.Version')->where($orderdetailwhere)->select();
		$this->assign("admindata",$admindata);
		$this->assign("userdata",$userdata);
		$this->assign("orderdetaildata",$orderdetaildata);
		$this->assign("orderdata",$orderdata);
		$this->display();
	}
}

?>